/*
 * 
 * LegendShop 多用户商城系统
 * 
 *  版权所有,并保留所有权利。
 * 
 */
package com.legendshop.oa.dao.impl;

import com.legendshop.dao.impl.GenericDaoImpl;
import com.legendshop.dao.support.EntityCriterion;
import com.legendshop.oa.dao.ProvinceDao;
import com.legendshop.oa.model.KeyValueEntity;
import com.legendshop.oa.model.Province;
import com.legendshop.oa.model.Region;

import java.util.ArrayList;
import java.util.List;

/**
 * The Class ProvinceDaoImpl.
 */
public class ProvinceDaoImpl extends GenericDaoImpl<Province, Integer> implements ProvinceDao {

	@Override
	public List<KeyValueEntity> getProvincesList() {
		List<Province> provinceList = this.queryAll();
		
		List<KeyValueEntity> result = new ArrayList<KeyValueEntity>();
		for (Province province : provinceList) {
			KeyValueEntity entity = new KeyValueEntity(province.getId(),province.getProvince());
			result.add(entity);
		}
		return result;
	}

	@Override
	public void deleteProvince(Integer id) {
		deleteById(id);
	}

	@Override
	public void updateProvince(Province province) {
		update(province);
	}

	@Override
	public List<Region> getRegionList() {
		return query("select distinct groupby as groupby from ls_provinces",Region.class);
	}

	@Override
	public Province getProvinceByProvinceid(String provinceid) {
		return this.getByProperties(new EntityCriterion().eq("provinceid", provinceid));
	}

	@Override
	public List<Province> getProvinceByName(String provinceName) {
		return this.query("select * from ls_provinces where province = ?", Province.class, provinceName);
	}

}
